package components {
	import UIFree.ObjectEvent;
	import UIFree.controls.popupMenu.uif_mainMenu;
	import UIFree.controls.popupMenu.uif_menuItem;
	import UIFree.controls.uif_popupMenu;
	import UIFree.uif_component;
	
	import classes.c_events;
	import classes.menu.c_defaultMenu;
	
	import components.tools.c_info;
	
	import flash.events.Event;
	import flash.geom.Rectangle;
	
	public class c_toolBar extends c_basePortBar {
		private var _menu: uif_mainMenu;
		public static const HEIGHT: int = 40;
		
		public function c_toolBar(parent:uif_component, mainMenu: Array) {
			super(parent, HEIGHT, c_basePortBar.TOP);
			_menu = new uif_mainMenu(this, mainMenu, {
				itemClass: uif_menuItem
			});
			
			_menu.addEvent(Event.SELECT, doMenuSelect);
			
			new c_info(this, 'info');
		}
		
		protected function doMenuSelect(e: ObjectEvent): void {
			if (e.object.event) cl.workspace.dispatchEvent(new ObjectEvent(e.object.event, e.object));
			else if (e.object.method) e.object.method();
		}
		
		public function isMyUIEvent(type: String): Boolean {
			var result: Boolean = false;
			function procItem(menuItem: Object, i: int, arr: Array): void {
				if (menuItem.event == type) result = true;
				if (menuItem.submenu) procList(menuItem.submenu);
			}
			
			function procList(a_list: Array): void {
				a_list.forEach(procItem);
			}
			
			procList(_menu.menuTree);
			return result;
		}
		
	}
}